import { BaseWindow } from "../../../component/window/BaseWindow";
import { ILayer } from "../../../mvc/interfaces/ILayer";
import { ObjCreate } from "../common/ObjCreate";
import { GTextFormat } from "../../../common/GTextFormat";
import { FontUtil } from "../../../common/font/FontUtil";
import { GlobalStyle } from "../../../common/global/GlobalStyle";
import { Language } from "../../../../extend/language/Language";
import { HandinMaterialRenderer } from "./HandinMaterialRenderer";
import { GModuleEvent } from "../../mvc/GModuleEvent";
import { ImagesConst } from "../../resource/ImagesConst";
import { DataEvent } from "../../events/DataEvent";
import { ItemData } from "../../resource/info/ItemData";
import { BaseItemNormal } from "../common/item/BaseItemNormal";
import { DataProvider } from "../../../../fl/data/DataProvider";
import { NpcEffectRule } from "../../rules/NpcEffectRule";
import { GTextFiled } from "../../../../com/mui/controls/GTextFiled";
import { GTileList } from "../../../../com/mui/controls/GTileList";
import { GLabel } from "../../../../com/mui/controls/GLabel";
type int = number;
//class BaseHandinMaterial
    
    export  class BaseHandinMaterial extends BaseWindow
    {
        constructor(arg1: ILayer=null)
        {
            super(arg1);
            this._materials = [];
            this.titleHeight = 25;
            this.updatePosition();
            return;
        }

        protected /* override */ createChildren(): void
        {
            super.createChildren();
            this._bg1 = ObjCreate.createBg(18, 38, 334, 100, this);
            this._bg2 = ObjCreate.createBg(18, 140, 334, 100, this);
            this._descText = ObjCreate.createGTextField("", 25, 45, 320, 150, this, new GTextFormat(FontUtil.songtiName, 12, GlobalStyle.color1Uint, null, null, null, null, null, flash.text.TextFormatAlign.LEFT, null, null, 24, 3));
            this._descText.multiline = true;
            this._descText.wordWrap = true;
            this._descText.autoSize = flash.text.TextFieldAutoSize.LEFT;
            this._descText.mouseWheelEnabled = false;
            this._label1 = ObjCreate.createLabel(Language.getString(69801), 25, 110, 300, 20, flash.text.TextFormatAlign.LEFT, this, true, 16776960);
            this._materialsPanel = ObjCreate.createTileList(40, 100, 300, 150, this);
            this._materialsPanel.columnWidth = 300;
            this._materialsPanel.rowHeight = 55;
            this._materialsPanel.setStyle("cellRenderer", HandinMaterialRenderer);
            this._materialsPanel.addEventListener(GModuleEvent.HandinMaterial, this.doHandinMaterial);
            this._handinNumLabel = ObjCreate.createLabel("", 0, 200, 340, 20, flash.text.TextFormatAlign.RIGHT, this, true, 16776960);
            this.updateHandinNum(0);
            this._line = ObjCreate.createBg(40, 200, 290, 2, this, ImagesConst.SplitLine);
            this._label2 = ObjCreate.createLabel(Language.getString(69800), 25, 150, 300, 20, flash.text.TextFormatAlign.LEFT, this, true, 16776960);
            return;
        }

        protected doHandinMaterial(arg1: DataEvent): void
        {
            return;
        }

        protected createRewards(arg1: Array<any>): void
        {
            var loc1=null;
            var loc2=0;
            var loc3=null;
            this._rewardsSp = new Object /* flash.display.Sprite */();
            this._rewardsSp.x = 45;
            this.addChild(this._rewardsSp);
            loc2 = 0;
            while (loc2 < 6) 
            {
                if (arg1.length > loc2) 
                {
                    loc1 = arg1[loc2] as ItemData;
                    (loc3 = new BaseItemNormal()).setSize(32, 32);
                    loc3.x = loc2 * 40;
                    loc3.y = 0;
                    loc3.itemData = loc1;
                    this._rewardsSp.addChild(loc3);
                }
                ++loc2;
            }
            return;
        }

        public updateOwnMaterials(): void
        {
            this._materialsPanel.dataProvider = this._materialsPanel.dataProvider;
            return;
        }

        public updateHandinNum(arg1: int): void
        {
            this._handinNumLabel.htmlText = Language.getStringByParam(69807, arg1);
            return;
        }

        protected set materials(arg1: Array<any>)
        {
            this._materials = arg1;
            this._materialsPanel.height = this._materials.length * 55 + 10;
            this._materialsPanel.dataProvider = new DataProvider(this._materials);
            return;
        }

        protected updatePosition(): void
        {
            this._bg1.height = this._descText.textHeight + 20;
            this._bg2.y = this._bg1.y + this._bg1.height + 3;
            this._bg2.height = this._materials.length * 55 + 135;
            this._label1.y = this._bg2.y + 10;
            this._materialsPanel.y = this._label1.y + 25;
            this._handinNumLabel.y = this._materialsPanel.y + this._materials.length * 55;
            this._line.y = this._handinNumLabel.y + 23;
            this._label2.y = this._line.y + 10;
            this._rewardsSp.y = this._label2.y + 25;
            this.setSize(370, this._bg1.height + this._bg2.height + 52);
            return;
        }

        public /* override */ show(arg1: int=0, arg2: int=0): void
        {
            super.show(arg1, arg2);
            NpcEffectRule.registDialogEffectWindow(this);
            return;
        }

        public /* override */ hide(): void
        {
            super.hide();
            NpcEffectRule.unRegistDialogEffectWindow(this);
            return;
        }

        protected /* var */_materials: Array<any>;

        protected /* var */_bg1: Object /* flash.display.Bitmap */;

        protected /* var */_bg2: Object /* flash.display.Bitmap */;

        protected /* var */_descText: GTextFiled;

        protected /* var */_materialsPanel: GTileList;

        protected /* var */_handinNumLabel: GLabel;

        protected /* var */_line: Object /* flash.display.Bitmap */;

        protected /* var */_label1: GLabel;

        protected /* var */_label2: GLabel;

        protected /* var */_rewardsSp: Object /* flash.display.Sprite */;
    }
